import dayjs from 'dayjs'
import 'dayjs/locale/zh-cn'
import calendar from 'dayjs/plugin/calendar'
import i18n from '@/lang'
const { t } = i18n.global
dayjs.extend(calendar)
dayjs.locale('zh-cn')
const dayjsCalendar = (val,option={})=>{
    return dayjs(val).calendar(null,{
        lastDay: `[${t('message.times.yesterday')}] HH:mm`,
        lastWeek: option.lastWeek || `MM${t('message.times.month')}DD${t('message.times.day')} HH:mm`,
        nextDay: `[${t('message.times.tomorrow')}] HH:mm`,
        nextWeek: option.nextWeek || `MM${t('message.times.month')}DD${t('message.times.day')} HH:mm`,
        sameDay: `[${t('message.times.today')}] HH:mm`,
        sameElse: isThisYear(val)?`MM${t('message.times.month')}DD${t('message.times.day')} HH:mm`:option.sameElse || `YYYY${t('message.times.year')}MM${t('message.times.month')}DD${t('message.times.day')} HH:mm`
    });
}
//判断时间是否是今年
function isThisYear(val) {
    if (val) {
        return dayjs().year() === new Date(val).getFullYear()
    }
}
export {
    dayjs,
    dayjsCalendar
}